package org.thread.test05.syn.homework.demo01;

/**
 * 取钱
 * @author CSY
 * @date 2025 - 03 - 12
 */
public class MyRunnable implements Runnable {
    private Account account;
    private double takeMoney;
    private String lock = "";

    public MyRunnable(){}

    public MyRunnable(Account account, double takeMoney) {
        this.account = account;
        this.takeMoney = takeMoney;
    }

    @Override
    public void run() {
        synchronized (lock) {
            if(account.getSurplus() < takeMoney){
                System.out.println("余额不足");
                return;
            }
            account.setSurplus(account.getSurplus() - takeMoney);
            System.out.println("取出"+takeMoney+"成功");
        }
    }
}
